__author__ = "Alexandre Lessard"
__copyright__ = "Copyright 2011, Alexandre Lessard"
__credits__ = ["Alexandre Lessard"]
__license__ = "BSD"
__version__ = "0.0.1"
__maintainer__ = "Alexandre Lessard"
__email__ = "alexandre.lessard.ti@gmail.com"
__status__ = "Prototype"


"""Model module fot the contacts table"""

#Import system
from simpleAppsSME import app

class ContactsModel:
    """Everything you need to manage contacts
    in the database."""
    
    def get_fields(self):
        """return the list of field names allowed for
        the Contacts informations based on the compagny
        that own the connected user"""
        fields = ('compagnyName', 'phone', 'address', 'notes')
        #collDefModel = app.factory.model('collection_definitions')
        #extraFields = collDefModel.get_fields(user,'contacts')
        return fields
        
    
    def get_all(self):
        return app.db.contacts.find()
    
    def get_all_by_status(self,status):
        pass
    
    def add(self,fields):
        post = {}
        allowedFields = ('compagnyName','phone')
        for fieldname in fields.keys():
            if fieldname in allowedFields:
                post[fieldname] = fields[fieldname]
        contactsTbl = app.db.contacts
        contactsTbl.insert(post)
            
    